import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    static Read scanner = new Read();

    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    static int[] elem = null;

    public static void main(String[] args) throws IOException {
        int[] array = new int[4];
        for (int i = 0; i < 4; i++) {
            array[i] = scanner.nextInt();
        }
        int m = scanner.nextInt();
        if (m == 0) {
            out.println(com(array[0], 12) * com(array[1], 12 - array[0])
                    * com(array[2], 12 - array[0] - array[1]) * com(array[3], 12 - array[0] - array[1] - array[2]));
        } else {
            //并查集
            init(12);
            while (m > 0) {
                int x = scanner.nextInt();
                int y = scanner.nextInt();
                merge(x, y);
                m--;
            }
            int[] counts = new int[13];
            for (int i = 1; i < elem.length; i++) {
                counts[getRoot(i)]++;
            }
            List<Integer> list = new ArrayList<>();
            for (int count : counts) {
                if (count > 1) {
                    list.add(count);
                }
            }
            out.println(dfs(array, list, 0, list.size()));

        }
        out.close();
    }

//    public static void main(String[] args) {
//        List<Integer>[] lists = new List[13];
//        lists[0] = List.of(1, 2, 6);
//        lists[1] = List.of(9, 10, 11);
//        int[] array = new int[]{1, 2, 4, 5};
//        System.out.println(dfs(array, lists, 0, 2));
//    }

    public static int dfs(int[] array, List<Integer> list, int index, int n) {
        if (index >= n) {
            //开始计算
            int sum = 0;
            for (int i = 0; i < 4; i++) {
                sum += array[i];
            }
            return com(array[0], sum) * com(array[1], sum - array[0])
                    * com(array[2], sum - array[0] - array[1]) * com(array[3], sum - array[0] - array[1] - array[2]);
        }

        int ans = 0;
        for (int i = 0; i < 4; i++) {
            if (list.get(index) <= array[i]) {
                //可以安排
                array[i] -= list.get(index);
                ans += dfs(array, list, index + 1, n);
                array[i] += list.get(index);
            }
        }
        return ans;
    }


    public static int com(int m, int n) {
        if (m == 0 || n == 0) {
            return 1;
        }
        return (n >= m) ? fac(n) / fac(n - m) / fac(m) : 0;
    }

    public static int fac(int n) {
        int res = 1;
        for (int i = 2; i <= n; i++) {
            res *= i;
        }
        return res;
    }

    public static void init(int n) {
        elem = new int[n + 1];
        for (int i = 1; i < elem.length; i++) {
            elem[i] = i;
        }
    }

    public static int getRoot(int i) {
        int temp = i;
        while (elem[i] != i) {
            i = elem[i];
        }
        if (elem[temp] != temp) {
            elem[temp] = i;
        }
        return i;
    }

    public static void merge(int i, int j) {
        if (i == j) {
            return;
        }
        int root1 = getRoot(i);
        elem[j] = root1;
    }
}


class Read {
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

    String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException {
        return bf.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}
